package com.hezuti.common.utils;

import java.util.Locale;
import java.util.ResourceBundle;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

/**
 * 读取配置文件工具类<br>
 * <b>Copyright</b> :Copyright (c) 2010<br>
 * 
 */
public class ConfigUtil {
	
	private static final String file = "config";

	private static final ConfigUtil instance = new ConfigUtil();

	private Log log = LogFactory.getLog(getClass());
	
	/**
	 * 构造函数
	 * @return
	 */
	public static ConfigUtil getInstance() {
		return instance;
	}

	/**
	 * load文件
	 * 
	 * @param file
	 * @return ResourceBundle
	 */
	public ResourceBundle loadFile(String file) {
		try {
			return ResourceBundle.getBundle(file, Locale.ENGLISH);
		} catch (Exception e) {
			log.error("[Property]:Can't Load property.properties" + e.toString());
			return null;
		}
	}

	/**
	 * 读取配置信息
	 * 
	 * @param key
	 * @return String
	 */
	public String getString(String key) {
		try {
			String value = loadFile(file).getString(key);
			return value;
		} catch (Exception e) {
			e.printStackTrace();
			return null;
		}
	}

}
